home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / srcuc.zip / LOOKUP.H < prev    next >
C/C++ Source or Header  |  1992-02-27  |  10KB  |  330 lines

  1. /* -*-C-*-
  2.  
  3. $Header: /scheme/src/microcode/RCS/lookup.h,v 9.47 1992/02/27 18:31:48 mhwu Exp $
  4.  
  5. Copyright (c) 1988-92 Massachusetts Institute of Technology
  6.  
  7. This material was developed by the Scheme project at the Massachusetts
  8. Institute of Technology, Department of Electrical Engineering and
  9. Computer Science.  Permission to copy this software, to redistribute
  10. it, and to use it for any purpose is granted, subject to the following
  11. restrictions and understandings.
  12.  
  13. 1. Any copy made of this software must include this copyright notice
  14. in full.
  15.  
  16. 2. Users of this software agree to make their best efforts (a) to
  17. return to the MIT Scheme project any improvements or extensions that
  18. they make, so that these may be included in future releases; and (b)
  19. to inform MIT of noteworthy uses of this software.
  20.  
  21. 3. All materials developed as a consequence of the use of this
  22. software shall duly acknowledge such use, in accordance with the usual
  23. standards of acknowledging credit in academic research.
  24.  
  25. 4. MIT has made no warrantee or representation that the operation of
  26. this software will be error-free, and MIT is under no obligation to
  27. provide any services, by way of maintenance, update, or otherwise.
  28.  
  29. 5. In conjunction with products arising from the use of this material,
  30. there shall be no use of the name of the Massachusetts Institute of
  31. Technology nor of any adaptation thereof in any advertising,
  32. promotional, or sales literature without prior written consent from
  33. MIT in each case. */
  34.  
  35. /* Macros and declarations for the variable lookup code. */
  36.  
  37. extern SCHEME_OBJECT
  38.   * EXFUN (deep_lookup, (SCHEME_OBJECT, SCHEME_OBJECT, SCHEME_OBJECT *)),
  39.   * EXFUN (lookup_fluid, (SCHEME_OBJECT)),
  40.   * EXFUN (force_definition, (SCHEME_OBJECT, SCHEME_OBJECT, long *));
  41.  
  42. extern long
  43.   EXFUN (deep_lookup_end, (SCHEME_OBJECT *, SCHEME_OBJECT *)),
  44.   EXFUN (deep_assignment_end,
  45.      (SCHEME_OBJECT *, SCHEME_OBJECT *, SCHEME_OBJECT, Boolean));
  46.  
  47. extern SCHEME_OBJECT
  48.   unbound_trap_object[],
  49.   uncompiled_trap_object[],
  50.   illegal_trap_object[],
  51.   fake_variable_object[];
  52.  
  53. #define GC_allocate_test(N)        GC_Check(N)
  54.  
  55. #define AUX_LIST_TYPE            TC_VECTOR
  56.  
  57. #define AUX_CHUNK_SIZE            20
  58. #define AUX_LIST_COUNT            ENV_EXTENSION_COUNT
  59. #define AUX_LIST_FIRST            ENV_EXTENSION_MIN_SIZE
  60. #define AUX_LIST_INITIAL_SIZE        (AUX_LIST_FIRST + AUX_CHUNK_SIZE)
  61.  
  62. /* Variable compilation types. */
  63.  
  64. #define LOCAL_REF            TC_NULL
  65. #define GLOBAL_REF            TC_UNINTERNED_SYMBOL
  66. #define FORMAL_REF            TC_CHARACTER
  67. #define AUX_REF                TC_FIXNUM
  68. #define UNCOMPILED_REF            TC_TRUE
  69.  
  70. /* Common constants. */
  71.  
  72. #ifdef b32                /* 32 bit objects */
  73.  
  74. #if (TYPE_CODE_LENGTH == 8)
  75. #define UNCOMPILED_VARIABLE        0x08000000
  76. #endif
  77.  
  78. #if (TYPE_CODE_LENGTH == 6)
  79. #define UNCOMPILED_VARIABLE        0x20000000
  80. #endif
  81.  
  82. #if (TC_TRUE != 0x08)
  83. #include "error:lookup.h and types.h are inconsistent"
  84. #endif
  85.  
  86. #endif /* b32 */
  87.  
  88. #ifndef UNCOMPILED_VARIABLE        /* Safe version */
  89. #define UNCOMPILED_VARIABLE        MAKE_OBJECT (UNCOMPILED_REF, 0)
  90. #endif
  91.  
  92. /* Macros for speedy variable reference. */
  93.  
  94. #if (LOCAL_REF == 0)
  95.  
  96. #define Lexical_Offset(Ind)        ((long) (Ind))
  97. #define Make_Local_Offset(Ind)        ((SCHEME_OBJECT) (Ind))
  98.  
  99. #else
  100.  
  101. #define Lexical_Offset(Ind)        OBJECT_DATUM (Ind)
  102. #define Make_Local_Offset(Ind)        MAKE_OBJECT (LOCAL_REF, Ind)
  103.  
  104. #endif
  105.  
  106. /* The code below depends on the following. */
  107.  
  108. /* Done as follows because of VMS. */
  109.  
  110. #define lookup_inconsistency_p                        \
  111.   ((VARIABLE_OFFSET == VARIABLE_COMPILED_TYPE) ||            \
  112.    (VARIABLE_FRAME_NO != VARIABLE_COMPILED_TYPE))
  113.  
  114. #if (lookup_inconsistency_p)
  115. #include "error: lookup.h inconsistency detected."
  116. #endif
  117.  
  118. #define get_offset(hunk) Lexical_Offset(MEMORY_FETCH (hunk[VARIABLE_OFFSET]))
  119.  
  120. #ifdef PARALLEL_PROCESSOR
  121.  
  122. #define verify(type_code, variable, code, label)            \
  123. {                                    \
  124.   variable = code;                            \
  125.   if (OBJECT_TYPE (MEMORY_FETCH (hunk[VARIABLE_COMPILED_TYPE])) !=    \
  126.       type_code)                            \
  127.     goto label;                                \
  128. }
  129.  
  130. #define verified_offset(variable, code)        variable
  131.  
  132. /* Unlike Lock_Cell, cell must be (SCHEME_OBJECT *).  This currently does
  133.    not matter, but might on a machine with address mapping.
  134.  */
  135.  
  136. #define setup_lock(handle, cell)        handle = Lock_Cell(cell)
  137. #define remove_lock(handle)            Unlock_Cell(handle)
  138.  
  139. /* This should prevent a deadly embrace if whole contiguous
  140.    regions are locked, rather than individual words.
  141.  */
  142.  
  143. #define setup_locks(hand1, cel1, hand2, cel2)                \
  144. {                                    \
  145.   if (LOCK_FIRST(cel1, cel2))                        \
  146.   {                                    \
  147.     setup_lock(hand1, cel1);                        \
  148.     setup_lock(hand2, cel2);                        \
  149.   }                                    \
  150.   else                                    \
  151.   {                                    \
  152.     setup_lock(hand2, cel2);                        \
  153.     setup_lock(hand1, cel1);                        \
  154.   }                                    \
  155. }
  156.  
  157. #define remove_locks(hand1, hand2)                    \
  158. {                                    \
  159.   remove_lock(hand2);                            \
  160.   remove_lock(hand1);                            \
  161. }
  162.  
  163. #else /* not PARALLEL_PROCESSOR */
  164.  
  165. #define verify(type_code, variable, code, label)
  166. #define verified_offset(variable, code)        code
  167. #define setup_lock(handle, cell)
  168. #define remove_lock(ignore)
  169. #define setup_locks(hand1, cel1, hand2, cel2)
  170. #define remove_locks(ign1, ign2)
  171.  
  172. #endif /* PARALLEL_PROCESSOR */
  173.  
  174. /* This is provided as a separate macro so that it can be made
  175.    atomic if necessary.
  176.  */
  177.  
  178. #define update_lock(handle, cell)                    \
  179. {                                    \
  180.   remove_lock(handle);                            \
  181.   setup_lock(handle, cell);                        \
  182. }
  183.  
  184. #ifndef Future_Variable_Splice
  185. /* Parameter list (Vbl, Ofs, Value) displeased some compilers */
  186. #define Future_Variable_Splice(a, b, c) 
  187. #endif
  188.  
  189. /* SCHEME_OBJECT *cell, env, *hunk; */
  190.  
  191. #define lookup(cell, env, hunk, label)                    \
  192. {                                    \
  193.   fast SCHEME_OBJECT frame;                        \
  194.                                     \
  195. label:                                    \
  196.                                     \
  197.   frame = (MEMORY_FETCH (hunk [VARIABLE_COMPILED_TYPE]));        \
  198.                                     \
  199.   switch (OBJECT_TYPE (frame))                        \
  200.   {                                    \
  201.     case GLOBAL_REF:                            \
  202.       /* frame is a pointer to the same symbol. */            \
  203.       cell = MEMORY_LOC (frame, SYMBOL_GLOBAL_VALUE);            \
  204.       break;                                \
  205.                                     \
  206.     case LOCAL_REF:                            \
  207.       cell = MEMORY_LOC (env, Lexical_Offset(frame));            \
  208.       break;                                \
  209.                                     \
  210.     case FORMAL_REF:                            \
  211.       lookup_formal(cell, env, hunk, label);                \
  212.                                     \
  213.     case AUX_REF:                            \
  214.       lookup_aux(cell, env, hunk, label);                \
  215.                                     \
  216.     default:                                \
  217.       /* Done here rather than in a separate case because of        \
  218.      peculiarities of the bobcat compiler.                \
  219.        */                                \
  220.       cell = ((OBJECT_TYPE (frame) == UNCOMPILED_REF) ?            \
  221.           uncompiled_trap_object :                    \
  222.           illegal_trap_object);                    \
  223.       break;                                \
  224.  }                                    \
  225. }
  226.  
  227. #define lookup_formal(cell, env, hunk, label)                \
  228. {                                    \
  229.   fast long depth;                            \
  230.                                     \
  231.   verify(FORMAL_REF, offset, get_offset(hunk), label);            \
  232.   depth = (OBJECT_DATUM (frame));                    \
  233.   frame = env;                                \
  234.   while(--depth >= 0)                            \
  235.   {                                    \
  236.     frame = FAST_MEMORY_REF (MEMORY_REF (frame, ENVIRONMENT_FUNCTION),    \
  237.                 PROCEDURE_ENVIRONMENT);            \
  238.   }                                    \
  239.                                     \
  240.   cell = MEMORY_LOC (frame,                        \
  241.             verified_offset(offset, get_offset(hunk)));    \
  242.                                     \
  243.   break;                                \
  244. }
  245.  
  246. #define lookup_aux(cell, env, hunk, label)                \
  247. {                                    \
  248.   fast long depth;                            \
  249.                                     \
  250.   verify(AUX_REF, offset, get_offset(hunk), label);            \
  251.   depth = (OBJECT_DATUM (frame));                    \
  252.   frame = env;                                \
  253.   while(--depth >= 0)                            \
  254.   {                                    \
  255.     frame = FAST_MEMORY_REF (MEMORY_REF (frame, ENVIRONMENT_FUNCTION),    \
  256.                 PROCEDURE_ENVIRONMENT);            \
  257.   }                                    \
  258.                                     \
  259.   frame = MEMORY_REF (frame, ENVIRONMENT_FUNCTION);            \
  260.   if (OBJECT_TYPE (frame) != AUX_LIST_TYPE)                \
  261.   {                                    \
  262.     cell = uncompiled_trap_object;                    \
  263.     break;                                \
  264.   }                                    \
  265.   depth = verified_offset(offset, get_offset(hunk));            \
  266.   if (depth > VECTOR_LENGTH (frame))                    \
  267.   {                                    \
  268.     cell = uncompiled_trap_object;                    \
  269.     break;                                \
  270.   }                                    \
  271.   frame = MEMORY_REF (frame, depth);                    \
  272.   if ((frame == SHARP_F) ||                        \
  273.       (FAST_PAIR_CAR (frame) != hunk[VARIABLE_SYMBOL]))            \
  274.   {                                    \
  275.     cell = uncompiled_trap_object;                    \
  276.     break;                                \
  277.   }                                    \
  278.   cell = PAIR_CDR_LOC (frame);                        \
  279.   break;                                \
  280. }
  281.  
  282. /* Macros and exports for incremental definition and hooks. */
  283.  
  284. extern long
  285.   EXFUN (extend_frame,
  286.      (SCHEME_OBJECT, SCHEME_OBJECT, SCHEME_OBJECT,
  287.       SCHEME_OBJECT, Boolean));
  288.  
  289. /* Definition recaches eagerly by default. */
  290.  
  291. #ifndef DEFINITION_RECACHES_LAZILY
  292. # ifndef DEFINITION_RECACHES_EAGERLY
  293. #  define DEFINITION_RECACHES_EAGERLY
  294. # endif
  295. #endif
  296.  
  297. #ifndef DEFINITION_RECACHES_EAGERLY
  298.  
  299. extern long
  300.   EXFUN (compiler_uncache, (SCHEME_OBJECT *, SCHEME_OBJECT));
  301.  
  302. #define simple_uncache(cell, sym)        PRIM_DONE
  303.  
  304. #define shadowing_recache(cell, env, sym, value, shadowed_p)        \
  305.   definition(cell, value, shadowed_p)
  306.  
  307. #define compiler_recache(old, new, env, sym, val, shadowed_p, link_p)    \
  308.   PRIM_DONE
  309.  
  310. #else /* DEFINITION_RECACHES_EAGERLY */
  311.  
  312. extern long
  313.   EXFUN (compiler_recache,
  314.      (SCHEME_OBJECT *, SCHEME_OBJECT *, SCHEME_OBJECT, SCHEME_OBJECT,
  315.       SCHEME_OBJECT, Boolean, Boolean));
  316.  
  317. extern SCHEME_OBJECT * shadowed_value_cell;
  318.  
  319. #define compiler_uncache(cell, sym)                    \
  320.   (shadowed_value_cell = cell, PRIM_DONE)
  321.  
  322. #define simple_uncache(cell, sym)                    \
  323.   compiler_uncache(cell, sym)
  324.  
  325. #define shadowing_recache(cell, env, sym, value, shadowed_p)        \
  326.   compiler_recache(shadowed_value_cell, cell, env, sym, value,        \
  327.              shadowed_p, false)
  328.  
  329. #endif /* DEFINITION_RECACHES_EAGERLY */
  330.